import request from '@/utils/request'
import {appConfig} from "../../config/app";
import JsEncrypt from "jsencrypt/bin/jsencrypt";
import '@/utils/sm/sm2';

let service = appConfig.microServModules.system + 'api/login'
let userService = appConfig.microServModules.system + 'api/user'
let basicService = appConfig.microServModules.system + 'api/basic'

export function login(data) {
  let res = {code: 0, data}
  return Promise.resolve(res)
}

export function getSmsCode(data) {
  return request(`${basicService}/sendValidMsgCode`, {method: 'get', data: data})
}

export function updateTenantPasswd(data) {
  return request(`${userService}/updateTenantPasswd`, {
    method: 'post',
    data: data
  })
}

export function updateInfo(data) {
  return request(`${userService}/updateInfo`, {
    method: 'post',
    data: data
  })
}

export function qryUserRefDetail(data) {
  return request(`${userService}/qryUserRefDetail`, {
    method: 'get',
    data: data
  })
}

export function validPhone(data) {
  return request(`${basicService}/validPhone`, {method: 'post', data: data})
}

export function qryPortalData(data) {
  return request(`${basicService}/qryPortalData`, {method: 'get', data: data})
}

export function getPwdStrategy(data) {
  return request(`${service}/passwdStrategy`, {
    method: 'get',
    data: data
  })
}

export function getPublicKey(username) {
  return request(`${service}/publicKey`, {
    method: 'get',
    headers: {opUser: encodeURIComponent(username)}
  })
}

export function checkJobNoMobileForXb(data) {
  return request(`${service}/checkJobNoMobile`, {
    method: 'post',
    data: data
  })
}

export function checkUserNumByMobileBeforeLoginForXb(data) {
  return request(`${service}/checkUserNumByMobileBeforeLogin`, {
    method: 'post',
    data: data
  })
}

export function afterCheckLogin(data) {
  return request(`${service}/afterCheckLoginForXb`, {
    method: 'post',
    data: data
  })
}




export function encryptPwd(publicKey, pwd) {
  if (publicKey.data.publicKey) {
    //if (publicKey.data.key.indexOf("rsa") !== -1) {
      let jsEncrypt = new JsEncrypt();
      jsEncrypt.setPublicKey(publicKey.data.publicKey);
      return jsEncrypt.encrypt(pwd);
   /* } else {
      return "04" + sm2.doEncrypt(pwd, publicKey.data.publicKey, 1);
    }*/
  }
}
